//
//  MyAlbumViewController.m
//  Findif
//
//  Created by Mac on 2018/11/6.
//  Copyright © 2018年 Cicel Chen. All rights reserved.
//

#import "MyAlbumViewController.h"
#import "MyAlbumCollectionViewCell.h"

@interface MyAlbumViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UIImagePickerControllerDelegate, UINavigationControllerDelegate>{
    
    UIImagePickerController *_imagePickerController;
}

@property (nonatomic, strong)UIButton * backButton;
@property (nonatomic, strong)UIButton * editButton;
@property (nonatomic, weak)UICollectionView * collectionView;
@property (nonatomic, weak)UIButton * updateButton;
@property (nonatomic, assign)BOOL isedit;
@property (nonatomic, strong)UIAlertController * alertVC;
@property (nonatomic, strong)NSArray * array;
@property (nonatomic, weak)UIImageView * backImageview;
@property (nonatomic, weak)UILabel * exploreLabel;

@end

@implementation MyAlbumViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = ZRWhiteColor;
    
    _imagePickerController = [[UIImagePickerController alloc] init];
    _imagePickerController.delegate = self;
    _imagePickerController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    _imagePickerController.allowsEditing = YES;
    
    [self loadData];
    [self setupNav];
    [self setupUI];
    [self setupAlertVC];
}

- (void)loadData{
    
    self.array = nil;
    
    if ([self.type isEqualToString:@"1"]) {
     //用户
        NSString * user_id = DEF_GET_OBJECT(@"id");
        
        [[ZRNetworkTool sharedTool] getUserPhotoAlbumWithUser_id:user_id ResultWithBlock:^(BOOL success, id responseData) {
            if (success) {
                
                self.array = responseData[@"data"];
            }
        }];
    }else if([self.type isEqualToString:@"2"]){
      //店铺
        NSString * shop_id = DEF_GET_OBJECT(@"shopid");
        
        [[ZRNetworkTool sharedTool] getMerchantsPhotoAlbumListsWithShop_id:shop_id WithIs_merchants_get:@"1" ResultWithBlock:^(BOOL success, id responseData) {
            
//            NSLog(@"res===%@",responseData);
            
            if (success) {
                
                
                self.array = responseData[@"data"];
            }
            
        }];
    }else if ([self.type isEqualToString:@"3"]){
        //社团
        
        [[ZRNetworkTool sharedTool] getGroupPhotoListWithGroup_id:self.group_id WithBlock:^(BOOL success, id responseData) {
            
            if (success) {
                
                self.array = responseData[@"data"];
            }
        }];
    }
    
    
}


- (void)setArray:(NSArray *)array{
    
    _array = array;
    
    [self.collectionView reloadData];
}

- (void)setupNav{
    
    self.title = @"相册";
    
    self.backButton = [[UIButton alloc] init];
    
    self.backButton.size = CGSizeMake(40 * SCREENH6, 30 * SCREENH6);
    [self.backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [self.backButton addTarget:self action:@selector(didNavButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.backButton setTitleColor:ZRBlackColor forState:UIControlStateNormal];
    self.backButton.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    UIBarButtonItem * leftBar = [[UIBarButtonItem alloc] initWithCustomView:self.backButton];
    
    self.navigationItem.leftBarButtonItem = leftBar;
    
    
    self.editButton = [[UIButton alloc] init];
    
    [self.editButton setTitle:@" 编辑 " forState:UIControlStateNormal];
    [self.editButton addTarget:self action:@selector(didNavButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.editButton setTitleColor:ZRBlackColor forState:UIControlStateNormal];
    self.editButton.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    UIBarButtonItem * rightBar = [[UIBarButtonItem alloc] initWithCustomView:self.editButton];
    
    self.navigationItem.rightBarButtonItem = rightBar;
}


- (void)setupUI{
    
    self.isedit = NO;
    
    //1.初始化layout
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init];
    //设置collectionView滚动方向
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
//    layout.itemSize =CGSizeMake(120 * SCREENH6, 120 * SCREENH6);
    layout.itemSize = CGSizeMake(117 * SCREENH6, 120 * SCREENH6);
//    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0 * SCREENH6);
    layout.sectionInset = UIEdgeInsetsMake(2, 2, 2, 2);
    
    UICollectionView * collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
    
    collectionView.backgroundColor = ZRWhiteColor;
    collectionView.showsHorizontalScrollIndicator = NO;
    //3.注册collectionViewCell
    //注意，此处的ReuseIdentifier 必须和 cellForItemAtIndexPath 方法中 一致 均为 cellId
    [collectionView registerClass:[MyAlbumCollectionViewCell class] forCellWithReuseIdentifier:@"MyAlbumCollectionViewCell"];
    //4.设置代理
    collectionView.delegate = self;
    collectionView.dataSource = self;
    //    [collectionView setContentOffset:CGPointMake(-30 * SCREENH6, 0)];
    
    self.collectionView = collectionView;
    
    [self.view addSubview:self.collectionView];
    
    
    UIButton * updateButton = [UIButton new];
    
    [updateButton setTitle:@"上传照片" forState:UIControlStateNormal];
    [updateButton setTitle:@"删除" forState:UIControlStateSelected];
    [updateButton setBackgroundColor:ColorWithRGB(0xFFE055)];
    [updateButton setTitleColor:ZRBlackColor forState:UIControlStateNormal];
    [updateButton setTitleColor:ZRWhiteColor forState:UIControlStateSelected];
    updateButton.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    [updateButton addTarget:self action:@selector(clickUpdatePicture) forControlEvents:UIControlEventTouchUpInside];
    
    self.updateButton = updateButton;
    
    [self.view addSubview:self.updateButton];
    
    
    UIImageView * backImageView = [UIImageView new];
    
    backImageView.image = [UIImage imageNamed:@"无相册"];
    
    self.backImageview = backImageView;
    
    [self.view addSubview:self.backImageview];
    
    
    UILabel * exploreLabel = [UILabel new];
    
    exploreLabel.textColor = [UIColor lightGrayColor];
    exploreLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    exploreLabel.text = @"亲，你的相册空空如也！\n赶快添加相片吧！";
    exploreLabel.textAlignment = NSTextAlignmentCenter;
    exploreLabel.numberOfLines = 2;
    
    self.exploreLabel = exploreLabel;
    
    [self.view addSubview:self.exploreLabel];
}

- (void)setupAlertVC{
    
    self.alertVC = [UIAlertController alertControllerWithTitle:@"" message:@"选择照片方式" preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction * camerAction = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        self->_imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        
        [self presentViewController:self->_imagePickerController animated:YES completion:nil];
    }];
    
    UIAlertAction * albumsAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        self->_imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        
        [self presentViewController:self->_imagePickerController animated:YES completion:nil];
    }];
    
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [self.alertVC addAction:camerAction];
    [self.alertVC addAction:albumsAction];
    [self.alertVC addAction:cancelAction];
    
}



- (void)viewDidLayoutSubviews{
    
    [self.backImageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(self.view).offset(155 * SCREENH6);
        make.width.mas_equalTo(175 * SCREENH6);
        make.height.mas_equalTo(144 * SCREENH6);
    }];
    
    [self.exploreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(self.backImageview.mas_bottom).offset(20 * SCREENH6);
    }];
    
    [self.updateButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.bottom.mas_equalTo(self.view).offset(-20 * SCREENH6);
        make.width.mas_equalTo(250 * SCREENH6);
        make.height.mas_equalTo(40 * SCREENH6);
    }];
}


#pragma mark collectionView代理方法

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    if (self.array.count == 0) {
        
        self.backImageview.hidden = NO;
        self.exploreLabel.hidden = NO;
    }else{
        
        self.backImageview.hidden = YES;
        self.exploreLabel.hidden = YES;
    }
    return self.array.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    MyAlbumCollectionViewCell *cell = (MyAlbumCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"MyAlbumCollectionViewCell" forIndexPath:indexPath];
    //设置数据
    if (self.array.count > 0) {
        
        if ([self.type isEqualToString:@"3"]) {
            
            NSDictionary * dict = self.array[indexPath.item];
            
            NSString * imgStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,dict[@"photo_img"]];
            NSURL * url = [NSURL URLWithString:imgStr];
            [cell.backImageView sd_setImageWithURL:url];
            cell.ID = [NSString stringWithFormat:@"%@",dict[@"id"]];
        }else{
            
            NSDictionary * dict = self.array[indexPath.item];
            
            NSString * imgStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,dict[@"img"]];
            NSURL * url = [NSURL URLWithString:imgStr];
            [cell.backImageView sd_setImageWithURL:url];
            cell.ID = [NSString stringWithFormat:@"%@",dict[@"id"]];
            if([[dict allKeys] containsObject:@"status"])
            {
                cell.status= [NSString stringWithFormat:@"%@",dict[@"status"]];
            }
        }
        
    }
    
    cell.gouImageView.hidden = YES;
    cell.state = NO;
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (self.isedit) {
        
        MyAlbumCollectionViewCell * cell = (MyAlbumCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
        
        cell.gouImageView.hidden = !cell.gouImageView.hidden;
        cell.state = !cell.gouImageView.hidden;

    }
    
}


- (void)clickUpdatePicture{
    
    if (self.updateButton.selected) {
        
        ShowHUD;
        
        NSMutableArray * array = [NSMutableArray array];
        
        for (MyAlbumCollectionViewCell *cell in self.collectionView.visibleCells) {
            
            if (cell.state) {
                
                NSString * ID = cell.ID;
                
                [array addObject:ID];
            }
        }    
        NSString *Album_id = [array componentsJoinedByString:@","];
        
        if ([self.type isEqualToString:@"1"]) {
           
            [[ZRNetworkTool sharedTool] deleteUserPhotoAlbumWithAlbum_id:Album_id ResultWithBlock:^(BOOL success, id responseData) {
                
                HiddenHUD;
                if (success) {
                    
                    self.isedit = NO;
                    
//                    self.backButton.size = CGSizeMake(11 * SCREENH6, 20 * SCREENH6);
                    [self.backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
                    [self.backButton setTitle:@"" forState:UIControlStateNormal];
                    [self.editButton setTitle:@" 编辑 " forState:UIControlStateNormal];
                    self.updateButton.selected = NO;
                    [self.updateButton setBackgroundColor:ColorWithRGB(0xFFE055)];
                    
                    for (MyAlbumCollectionViewCell *cell in self.collectionView.visibleCells) {
                        
                        cell.backImageView.userInteractionEnabled = YES;
                        cell.gouImageView.hidden = YES;
                        cell.state = NO;
                    }
                    [self loadData];
                }else{
                    
                    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                                   message:responseData[@"message"]
                                                                            preferredStyle:UIAlertControllerStyleAlert];
                    
                    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                          handler:^(UIAlertAction * action) {
                                                                              
                                                                              
                                                                          }];
                    
                    [alert addAction:defaultAction];
                    [self presentViewController:alert animated:YES completion:nil];
                }
            }];
        }else if([self.type isEqualToString:@"2"]){
            
            NSString * shop_id = DEF_GET_OBJECT(@"shopid");
            
            [[ZRNetworkTool sharedTool] deleteMerchantsPhotoAlbumWithShop_id:shop_id WithID:Album_id ResultWithBlock:^(BOOL success, id responseData) {
                
                HiddenHUD;
                if (success) {
                    
                    self.isedit = NO;
                    
//                    self.backButton.size = CGSizeMake(11 * SCREENH6, 20 * SCREENH6);
                    [self.backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
                    [self.backButton setTitle:@"" forState:UIControlStateNormal];
                    [self.editButton setTitle:@" 编辑 " forState:UIControlStateNormal];
                    self.updateButton.selected = NO;
                    [self.updateButton setBackgroundColor:ColorWithRGB(0xFFE055)];
                    
                    for (MyAlbumCollectionViewCell *cell in self.collectionView.visibleCells) {
                        
                        cell.backImageView.userInteractionEnabled = YES;
                        cell.gouImageView.hidden = YES;
                        cell.state = NO;
                    }
                    [self loadData];
                }else{
                    
                    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                                   message:responseData[@"message"]
                                                                            preferredStyle:UIAlertControllerStyleAlert];
                    
                    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                          handler:^(UIAlertAction * action) {
                                                                              
                                                                              
                                                                          }];
                    
                    [alert addAction:defaultAction];
                    [self presentViewController:alert animated:YES completion:nil];
                }
            }];
        }else if([self.type isEqualToString:@"3"]){
            
            [[ZRNetworkTool sharedTool] deleteGroupPhotoWithID:Album_id WithBlock:^(BOOL success, id responseData) {
                
                HiddenHUD;
                if (success) {
                    
                    self.isedit = NO;
                    
                    //                    self.backButton.size = CGSizeMake(11 * SCREENH6, 20 * SCREENH6);
                    [self.backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
                    [self.backButton setTitle:@"" forState:UIControlStateNormal];
                    [self.editButton setTitle:@" 编辑 " forState:UIControlStateNormal];
                    self.updateButton.selected = NO;
                    [self.updateButton setBackgroundColor:ColorWithRGB(0xFFE055)];
                    
                    for (MyAlbumCollectionViewCell *cell in self.collectionView.visibleCells) {
                        
                        cell.backImageView.userInteractionEnabled = YES;
                        cell.gouImageView.hidden = YES;
                        cell.state = NO;
                    }
                    [self loadData];
                }else{
                    
                    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                                   message:responseData[@"message"]
                                                                            preferredStyle:UIAlertControllerStyleAlert];
                    
                    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                          handler:^(UIAlertAction * action) {
                                                                              
                                                                              
                                                                          }];
                    
                    [alert addAction:defaultAction];
                    [self presentViewController:alert animated:YES completion:nil];
                }
            }];
        }
        
        
    }else{
        
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
            
            self.alertVC.popoverPresentationController.sourceView = self.view;
            self.alertVC.popoverPresentationController.sourceRect = CGRectMake(10 * SCREENH6,kScreenH - 150 * SCREENH6,355 * SCREENH6,150 * SCREENH6);
            //            self.alertVC.modalPresentationStyle = UIModalPresentationFormSheet;
        }
        
        [self presentViewController:self.alertVC animated:YES completion:nil];
    }
   
}

#pragma mark -实现图片选择器代理
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissViewControllerAnimated:YES completion:^{}];
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    
    NSString * user_id = DEF_GET_OBJECT(@"id");
    NSData *frontImageData = UIImageJPEGRepresentation(image,0.5);
    NSString *base64Data = [frontImageData base64EncodedStringWithOptions:0];
    NSString * reslut = [NSString stringWithFormat:@"data:image/jpeg;base64,%@",base64Data];
    
    if ([self.type isEqualToString:@"1"]) {
        
        NSDictionary * dic = @{@"img":reslut,@"user_id":user_id};
        
        [[NetworkTool sharedTools] POST:@"Api/uploadUserPhotoAlbum" parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            int code = [responseObject[@"code"] intValue];
            
            if (code == 200) {
                
                [self loadData];
            }
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
        }];
        
    }else if([self.type isEqualToString:@"2"]){
        
        [[ZRNetworkTool sharedTool] uploadOneImgResultWithImg:reslut WithBlock:^(BOOL success, id responseData) {
            
            if (success) {
                
                NSString * string = [NSString stringWithFormat:@"%@",responseData[@"data"]];
                
                [self addMerchantsPhotoAlbumWithImg:string];
            }else{
                
                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:responseData[@"message"]
                                                                        preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {
                                                                          
                                                                      }];
                
                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }
        }];
    }else if ([self.type isEqualToString:@"3"]){
        
        [[ZRNetworkTool sharedTool] uploadOneImgResultWithImg:reslut WithBlock:^(BOOL success, id responseData) {
            
            if (success) {
                
                NSString * string = [NSString stringWithFormat:@"%@",responseData[@"data"]];
                
                [self addGroupImageWithImg:string];
            }else{
                
                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:responseData[@"message"]
                                                                        preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {
                                                                          
                                                                      }];
                
                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }
        }];
    }
}

//当用户取消选择的时候，调用该方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:^{}];
}



- (void)didNavButton:(UIButton *)button{
    
    if (button == self.backButton) {
        
        if (!self.isedit) {
            
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            
            self.isedit = NO;
            
//            self.backButton.size = CGSizeMake(11 * SCREENH6, 20 * SCREENH6);
            [self.backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
            [self.backButton setTitle:@"" forState:UIControlStateNormal];
            [self.editButton setTitle:@" 编辑 " forState:UIControlStateNormal];
            self.updateButton.selected = NO;
            [self.updateButton setBackgroundColor:ColorWithRGB(0xFFE055)];
            
            for (MyAlbumCollectionViewCell *cell in self.collectionView.visibleCells) {
                
                cell.backImageView.userInteractionEnabled = YES;
                cell.gouImageView.hidden = YES;
                cell.state = NO;
            }
        }
    }else{
        
        if (!self.isedit) {
            
            if (self.array.count == 0) {
                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:@"你还没有图片，不能进行编辑"
                                                                        preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {
                                                                          
                                                                      }];
                
                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }else{
                
                self.isedit = YES;
                
                //            self.backButton.size = CGSizeMake(40 * SCREENH6, 30 * SCREENH6);
                [self.backButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
                [self.backButton setTitle:@" 取消 " forState:UIControlStateNormal];
                [self.editButton setTitle:@" 全选 " forState:UIControlStateNormal];
                self.updateButton.selected = YES;
                [self.updateButton setBackgroundColor:ZRBlackColor];
                
                for (MyAlbumCollectionViewCell *cell in self.collectionView.visibleCells) {
                    
                    cell.backImageView.userInteractionEnabled = NO;
                }
            }
           
        }else{
            
            for (MyAlbumCollectionViewCell *cell in self.collectionView.visibleCells) {
                
                cell.gouImageView.hidden = NO;
                cell.state = YES;
            }
        }
    }
}


- (void)addGroupImageWithImg:(NSString *)img{
    
//    NSLog(@"img==%@",img);
    
    NSDictionary * dict = @{@"group_id":self.group_id,@"photo_img":img};
    
    [[ZRNetworkTool sharedTool] addGroupPhotoWithDict:dict WithBlock:^(BOOL success, id responseData) {
       
        if (success) {
            
            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                           message:responseData[@"message"]
                                                                    preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                  handler:^(UIAlertAction * action) {
                                                                      
                                                                      [self loadData];
                                                                  }];
            
            [alert addAction:defaultAction];
            [self presentViewController:alert animated:YES completion:nil];
            
            
        }else{
            
            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                           message:responseData[@"message"]
                                                                    preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                  handler:^(UIAlertAction * action) {
                                                                      
                                                                  }];
            
            [alert addAction:defaultAction];
            [self presentViewController:alert animated:YES completion:nil];
        }
    }];
}


- (void)addMerchantsPhotoAlbumWithImg:(NSString *)img{

    NSString * shop_id = DEF_GET_OBJECT(@"shopid");
    
    [[ZRNetworkTool sharedTool] addMerchantsPhotoAlbumWithShop_id:shop_id WithImg:img ResultWithBlock:^(BOOL success, id responseData) {
        
        if (success) {
            
            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                           message:@"恭喜你上传成功，请等待审核。"
                                                                    preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                  handler:^(UIAlertAction * action) {
                                                                      
                                                                  }];
            
            [alert addAction:defaultAction];
            [self presentViewController:alert animated:YES completion:nil];
            
            [self loadData];
        }else{
            
            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                           message:responseData[@"message"]
                                                                    preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                  handler:^(UIAlertAction * action) {
                                                                      
                                                                  }];
            
            [alert addAction:defaultAction];
            [self presentViewController:alert animated:YES completion:nil];
        }
    }];
}

#pragma mark - TableView 占位图
- (NSString *)xy_noDataViewMessage {
    
    return @"";
}

- (UIColor *)xy_noDataViewMessageColor {
    
    return [UIColor blackColor];
}

@end
